package com.shiguiwu.springboot3.feign;

import com.shiguiwu.springboot3.dto.UserDTO;
import com.shiguiwu.springboot3.util.R;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.client.circuitbreaker.NoFallbackAvailableException;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @description: user
 * @author: stone
 * @date: Created by 2023/7/16 22:27
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springboot3.feign
 */


//@CircuitBreaker(name = "system")
@FeignClient(value = "system")
public interface UserFeignApi {

    public static Logger LOGGER = LoggerFactory.getLogger(UserFeignApi.class);
    @GetMapping("/user/test2")
    String testBatch();

    //@CircuitBreaker(name = "system", fallbackMethod = "fallback")
    @GetMapping(value = "/user/test3")
    Integer test3();

    default Integer fallback(Throwable throwable) {
        LOGGER.error("出现异常了===> {}", throwable.getMessage());
        return -1;
    }

    @GetMapping(value = "/user/test4")
    UserDTO test4();

    @GetMapping(value = "/user/test5")
    UserDTO test5();

    @GetMapping(value = "/user/test5")
    R<UserDTO> test6();

    @GetMapping(value = "/user/timeout")
    R<UserDTO> timeout(@RequestParam long time);

    @GetMapping(value = "/user/ex")
    R<Integer> ex(@RequestParam long time);



    //@Component 启动报错

    //@Slf4j
    //class UserFeignApiFallback implements UserFeignApi {
    //
    //    @Override
    //    public String testBatch() {
    //        return null;
    //    }
    //
    //    @Override
    //    public Integer test3() {
    //        return null;
    //    }
    //
    //    @Override
    //    public UserDTO test4() {
    //        return null;
    //    }
    //
    //    @Override
    //    public UserDTO test5() {
    //        return null;
    //    }
    //
    //    @Override
    //    public R<UserDTO> test6() {
    //        return null;
    //    }
    //
    //    @Override
    //    public R<UserDTO> timeout(long time) {
    //        return null;
    //    }
    //
    //    @Override
    //    public R<Integer> ex(long time) {
    //        log.error("异常=================> {}", time);
    //        throw new NoFallbackAvailableException("Boom!", new RuntimeException());
    //    }
    //}
}

